package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "商店相关接口")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result setStatus(@PathVariable String status){
        log.info("设置营业状态：{}", status.equals("1") ? "营业中" : "打样中");
        //创建操作字符串的redis对象
        ValueOperations valueOperations = redisTemplate.opsForValue();

        // set key value, 设置指定的key值
        valueOperations.set("SHOP_STATUS", status);
        return Result.success();
    }


    @GetMapping("/status")
    @ApiOperation("查询营业状态")
    public Result<String> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String status = (String) valueOperations.get("SHOP_STATUS");
        log.info("当前营业状态：{}", status.equals("1") ? "营业中" : "打样中");

        return Result.success(status);
    }



}
